package com.evil.application.pojo.dto.reporting;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.evil.application.enums.reporting.ReportingStyleTypeEnum;
import com.evil.application.enums.reporting.ReportingTypeEnum;
import com.evil.application.pojo.entity.ApplicationReporting;
import com.evil.common.application.dto.permission.app.AppPermissionsListDTO;
import com.evil.common.application.enums.QueryTypeEnum;
import com.evil.common.account.dto.user.UserBaseRespDTO;
import com.evil.common.core.enums.SwitchEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.Date;

/**
 * 应用报表基础信息 返回实体
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ApplicationReportingBaseDTO extends AppPermissionsListDTO {

    /**
     * id
     */
    @JSONField(serialize = false)
    private Long reportingId;

    /**
     * 应用id
     */
    @JSONField(serialize = false)
    private Long applicationId;

    /**
     * 应用key
     */
    private String applicationKey;

    /**
     * 报表key
     */
    @NotBlank(message = "报表key不能为空")
    private String reportingKey;

    /**
     * 表单名称
     */
    private String reportingName;

    /**
     * 报表类型（0-未知，1-数据表，2-指标卡，3-柱状表，4-折线图，5-饼状图）
     */
    private Integer reportingType;

    /**
     * 备注开关(0-关闭, 1-开启)
     */
    private Integer remarkStatus;

    /**
     * 备注
     */
    private String remark;

    /**
     * 创建人
     */
    @JSONField(serialize = false)
    private Long creatorId;
    private UserBaseRespDTO creator;

    /**
     * 创建时间
     */
    private Date created;

    public ApplicationReportingBaseDTO() {
        super();
        this.reportingType = ReportingTypeEnum.DATA_CHART.getId();
        this.remarkStatus = SwitchEnum.NO.getId();
    }

    public ApplicationReportingBaseDTO(ApplicationReporting applicationReporting) {
        super();
        this.reportingId = applicationReporting.getReportingId();
        this.applicationId = applicationReporting.getApplicationId();
        this.reportingKey = applicationReporting.getReportingKey();
        this.reportingName = applicationReporting.getReportingName();
        this.reportingType = applicationReporting.getReportingType();
        this.remarkStatus = applicationReporting.getRemarkStatus();
        this.remark = applicationReporting.getRemark();
        this.creatorId = applicationReporting.getCreatorId();
        this.created = applicationReporting.getCreated();
        super.setPermissionStatus(applicationReporting.getPermissionStatus());
    }

    public ApplicationReporting createApplicationReporting() {
        ApplicationReporting applicationReporting = new ApplicationReporting();
        applicationReporting.setReportingId(this.reportingId);
        applicationReporting.setApplicationId(this.applicationId);
        applicationReporting.setReportingKey(this.reportingKey);
        // 复制属性
        this.copyProps(applicationReporting);

        return applicationReporting;
    }

    public void copyProps(ApplicationReporting applicationReporting) {
        applicationReporting.setReportingName(this.reportingName);
        applicationReporting.setReportingType(this.reportingType);
        applicationReporting.setRemarkStatus(this.remarkStatus);
        applicationReporting.setRemark(this.remark);
        applicationReporting.setPermissionStatus(super.getPermissionStatus());

        applicationReporting.setReportingHeaders(JSON.toJSONString(new ArrayList<>()));
        applicationReporting.setReportingColumnHeaders(JSON.toJSONString(new ArrayList<>()));
        applicationReporting.setReportingTargets(JSON.toJSONString(new ArrayList<>()));
        applicationReporting.setSorts(JSON.toJSONString(new ArrayList<>()));
        applicationReporting.setRankingStatus(SwitchEnum.NO.getId());
        applicationReporting.setRankingConfig(JSON.toJSONString(new ReportingRankingConfigDTO()));
        applicationReporting.setStyleType(ReportingStyleTypeEnum.DEFAULT.getId());
        applicationReporting.setPermissionConfig(JSON.toJSONString(new ReportingPermissionConfigDTO()));


        applicationReporting.setReportingHeaders(JSON.toJSONString(new ArrayList<>()));
        applicationReporting.setReportingColumnHeaders(JSON.toJSONString(new ArrayList<>()));
        applicationReporting.setReportingTargets(JSON.toJSONString(new ArrayList<>()));
        applicationReporting.setSortStatus(SwitchEnum.NO.getId());
        applicationReporting.setSorts(JSON.toJSONString(new ArrayList<>()));
        applicationReporting.setRankingStatus(SwitchEnum.NO.getId());
        applicationReporting.setRankingConfig(JSON.toJSONString(new ReportingRankingConfigDTO()));
        applicationReporting.setStyleType(ReportingStyleTypeEnum.DEFAULT.getId());
        applicationReporting.setPermissionConfig(JSON.toJSONString(new ReportingPermissionConfigDTO()));
        applicationReporting.setFilterStatus(SwitchEnum.NO.getId());
        applicationReporting.setQueryStatus(SwitchEnum.NO.getId());
        applicationReporting.setQueryType(QueryTypeEnum.ACCURATE.getId());
        applicationReporting.setQueryConfig(JSON.toJSONString(new QueryConfigDTO()));
        applicationReporting.setControlPermissionStatus(SwitchEnum.NO.getId());
    }

}
